package com.example.testapp.activity.util;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;

import com.example.testapp.R;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

/**
 * Created by l on 2016/8/2.
 */
public class SystemUtils {

    public static void shareApp(Activity  mActivity) {
        String shareAppContent="各位亲爱的小伙伴们，我发现了一款简约好用且颜值爆表的天气APP酷我天气，分享给大家,福利多多哦！";

        new File(mActivity.getFilesDir(), "share.png").deleteOnExit();
        FileOutputStream fileOutputStream=null;
        try {
            fileOutputStream = mActivity.openFileOutput("share.png", 1);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        Bitmap pic=BitmapFactory.decodeResource(mActivity.getResources(),R.mipmap.cool_weather_icon);
        pic.compress(Bitmap.CompressFormat.JPEG, 100,fileOutputStream);

        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("image/*");
        intent.putExtra("sms_body", shareAppContent);
        intent.putExtra(Intent.EXTRA_TEXT,shareAppContent);
        intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(mActivity.getFilesDir(), "share.png")));
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        mActivity.startActivity(Intent.createChooser(intent, "分享"));
    }
}
